package com.retail.system.controller;

import cn.hutool.core.util.ObjectUtil;
import com.retail.core.common.AbstractCommonController;
import com.retail.core.entity.ParamReq;
import com.retail.core.entity.result.PageResult;
import com.retail.core.entity.result.Result;
import com.retail.global.annon.TraceLog;
import com.retail.global.security.LoginUserUtil;
import com.retail.system.entity.request.ProjectRequest;
import com.retail.system.entity.vo.ProjectVo;
import com.retail.system.service.ProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @author Administrator
*/
@Api(tags = "项目API")
@RestController
@RequestMapping("/project")
public class ProjectController extends AbstractCommonController<ProjectService, ProjectRequest, ProjectVo>{

    private ProjectService projectService;

    public ProjectController(ProjectService iconService) {
        this.projectService = iconService;
    }

    @ApiOperation("详情")
    @TraceLog()
    @GetMapping("{id}")
    public Result getModel(@PathVariable("id") Long id) {
        return super.getModel(projectService, id);
    }

    @CrossOrigin
    @TraceLog()
    @PostMapping("getOneModel")
    public Result getOneModel(@RequestBody ProjectRequest request){
        return Result.success(projectService.getOneModel(request));
    }

    @TraceLog()
    @PostMapping
    @ApiOperation("生成项目信息")
    public Result<Integer> save(@RequestBody ProjectRequest iconRequest) {
        if (ObjectUtil.isNotEmpty(iconRequest) && ObjectUtil.isEmpty(iconRequest.getId())) {
        return super.save(projectService, iconRequest);
        } else {
            return super.update(projectService, iconRequest);
        }
    }

    @TraceLog()
    @PutMapping
    @ApiOperation("更新项目信息")
    public Result<Integer> update(@RequestBody ProjectRequest iconRequest) {
        return super.update(projectService, iconRequest);
    }

    @TraceLog()
    @PostMapping("listPage")
    @ApiOperation("项目信息列表")
    public Result<List<ProjectVo>> listPage(@RequestBody ParamReq<ProjectRequest> req)  {
        return super.listPage(projectService, req);
    }

    @TraceLog()
    @PostMapping("countPage")
    @ApiOperation("项目信息列表-统计")
    public Result<Integer> countPage(@RequestBody ParamReq<ProjectRequest> req)  {
        return super.countPage(projectService, req);
    }

    @TraceLog()
    @PostMapping("page")
    @ApiOperation("项目信息列表-分页数据")
    public Result<PageResult> page(@RequestBody ParamReq<ProjectRequest> req)  {
        return super.page(projectService, req);
    }

    @TraceLog()
    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除项目信息")
    public Result<Integer> delete(@PathVariable("id") Long id) {
        return super.delete(projectService, id);
    }

    @TraceLog()
    @ApiOperation("批量删除项目信息")
    @DeleteMapping("{ids}")
    public Result<Integer> batchDelete(@PathVariable("ids") List<Long> ids) {
        return super.batchDelete(projectService, ids);
    }

    @Override
    public Long getLoginUserId() {
        return LoginUserUtil.getUserId();
    }
}
